<extend name="Public/base"/>

<block name="body">
  <!-- 标题 -->
  <div class="main-title">
    <h2>优惠券发放记录({$_total})</h2>
  </div>

  <!-- 按钮工具栏 -->
  <div class="cf">
    <div class="fl">
      <a class="btn" href="{:U('Coupon/index')}">新 增</a>
      <button class="btn ajax-post confirm" url="{:U('del')}" target-form="ids">删 除</button>
    </div>
  </div>
  
  <!-- 数据表格 -->
  <div class="data-table">
    <div style="display: none;">
      {:hook('itemSelect', array('name' => 'items', 'value' => '', 'tpl' => 'couponView'))}
    </div>
    <table>
      <thead>
        <tr>
          <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
          <th>领取用户</th>
          <th>优惠券编号</th>
          <th>优惠券名称</th>
          <th>优惠券金额</th>
          <th>适用商品</th>
          <th>适用限额</th>
          <th>发放时间</th>
          <th>使用时间</th>
          <th width="40">操作</th>
        </tr>
      </thead>
      <tbody>
        <notempty name="list">
          <volist name="list" id="vo">
            <tr>
              <td><input class="ids" type="checkbox" name="ids[]" value="{$vo.id}" /></td>
              <td>{$vo['uid']|get_nickname}</td>
              <td>{$vo['coupon_num']}</td>
              <td>{$vo['coupon']['name']}</td>
              <td>{$vo['coupon']['amount']}</td>
              <td><notempty name="vo.coupon.items"><a href="javascript:setItems('{$vo['coupon']['id']}', '{$vo['coupon']['items']}');">点击查看</a><else/>全场通用</notempty></td>
              <td>{$vo['coupon']['norm']}</td>
              <td>{$vo['create_time']|time_format}</td>
              <td><notempty name="vo.use_time">{$vo['use_time']|time_format}<else/>尚未使用</notempty></td>
              <td>
                <a href="{:U('del?ids='.$vo['id'])}" class="confirm ajax-get">[删除]</a>
              </td>
            </tr>
          </volist>
        <else/>
          <tr><td colspan="9" class="text-center"> 尚未给任何用户发放优惠券!  <a href="{:U('CouponUser/add',array('id'=>I('get.id')))}" class="btn btn-mini">&plus;立即发放</a></td></tr>
        </notempty>
      </tbody>
    </table> 
  </div>

  <!-- 分页 -->
  <div class="page">
    {$_page}
  </div>
</block>

<block name="script">
  <script type="text/javascript" language="javascript">
    function setItems(coupon_id, items){
      $('.J_current_items').val(items);
      $('#coupon_id').val(coupon_id);

      var items_array = items.split(',');
      var item_count = items_array.length;
      var item_json = '{';
      for(i=0; i < item_count; i++){
        item_json = item_json + '"' + items_array[i] + '":' + '"' + items_array[i] + '"';
        if(i < item_count -1){
          item_json = item_json + ',';
        }
      }
      item_json = item_json + '}';

      if(item_count > 0){
        var data = {
          current_items:JSON.parse(item_json),
          selectedCount:item_count
        }
      }
      selectItem.load(data);
    }
    //导航高亮
    highlight_subnav('{:U("Coupon/index")}');
  </script>
</block>
